<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>用户地址代码 | 美多商城</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../C03-Goods/index.html" />
    
    
    <link rel="prev" href="../../C02-Users/Address/UserAddressManagement.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.15.4"
        data-chapter-title="用户地址代码"
        data-filepath="C02-Users/Address/UserAddressCode.md"
        data-basepath="../.."
        data-revision="Sat Aug 11 2018 20:09:13 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        美多商城
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Prepare/index.html">
            
                
                    <a href="../../C01-Prepare/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Prepare/BusinessModel.html">
            
                
                    <a href="../../C01-Prepare/BusinessModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        商业模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Prepare/DevelopmentProcess.html">
            
                
                    <a href="../../C01-Prepare/DevelopmentProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        开发流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Prepare/ProductAnalysis.html">
            
                
                    <a href="../../C01-Prepare/ProductAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        需求分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-Prepare/ProjectStructure.html">
            
                
                    <a href="../../C01-Prepare/ProjectStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        项目架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-Prepare/StartProject.html">
            
                
                    <a href="../../C01-Prepare/StartProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        创建工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-Prepare/Config.html">
            
                
                    <a href="../../C01-Prepare/Config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Users/index.html">
            
                
                    <a href="../../C02-Users/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        用户部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Users/UserModel.html">
            
                
                    <a href="../../C02-Users/UserModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        用户模型类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Users/RegisterAnalysis.html">
            
                
                    <a href="../../C02-Users/RegisterAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        注册业务接口分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Users/ImageCode.html">
            
                
                    <a href="../../C02-Users/ImageCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        图片验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Users/SMSCode.html">
            
                
                    <a href="../../C02-Users/SMSCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        短信验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Users/CORS.html">
            
                
                    <a href="../../C02-Users/CORS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        跨域CORS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Users/CelerySendSMSCode.html">
            
                
                    <a href="../../C02-Users/CelerySendSMSCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        使用Celery发送短信
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Users/AccountExistingCheck.html">
            
                
                    <a href="../../C02-Users/AccountExistingCheck.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        判断帐号是否存在
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Users/Register.html">
            
                
                    <a href="../../C02-Users/Register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="C02-Users/JWT.html">
            
                
                    <a href="../../C02-Users/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="C02-Users/DRF-JWT.html">
            
                
                    <a href="../../C02-Users/DRF-JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        Django REST framework JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="C02-Users/Login.html">
            
                
                    <a href="../../C02-Users/Login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="C02-Users/QQLogin/index.html">
            
                
                    <a href="../../C02-Users/QQLogin/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        QQ登录
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.12.1" data-path="C02-Users/QQLogin/Step1.html">
            
                
                    <a href="../../C02-Users/QQLogin/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12.2" data-path="C02-Users/QQLogin/Step2.html">
            
                
                    <a href="../../C02-Users/QQLogin/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12.3" data-path="C02-Users/QQLogin/Step3.html">
            
                
                    <a href="../../C02-Users/QQLogin/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="C02-Users/UserInfo.html">
            
                
                    <a href="../../C02-Users/UserInfo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.13.</b>
                        
                        用户中心个人信息
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="C02-Users/Email/index.html">
            
                
                    <a href="../../C02-Users/Email/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.</b>
                        
                        邮件与验证
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.14.1" data-path="C02-Users/Email/DjangoEmail.html">
            
                
                    <a href="../../C02-Users/Email/DjangoEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.1.</b>
                        
                        Django发送邮件的方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14.2" data-path="C02-Users/Email/SendEmail.html">
            
                
                    <a href="../../C02-Users/Email/SendEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.2.</b>
                        
                        保存邮箱并发送验证邮件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14.3" data-path="C02-Users/Email/VerifyEmail.html">
            
                
                    <a href="../../C02-Users/Email/VerifyEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.3.</b>
                        
                        验证邮箱链接
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="C02-Users/Address/index.html">
            
                
                    <a href="../../C02-Users/Address/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.</b>
                        
                        收货地址
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.15.1" data-path="C02-Users/Address/AreaSelect.html">
            
                
                    <a href="../../C02-Users/Address/AreaSelect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.1.</b>
                        
                        省市区地址查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15.2" data-path="C02-Users/Address/Cache.html">
            
                
                    <a href="../../C02-Users/Address/Cache.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.2.</b>
                        
                        使用缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15.3" data-path="C02-Users/Address/UserAddressManagement.html">
            
                
                    <a href="../../C02-Users/Address/UserAddressManagement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.3.</b>
                        
                        用户地址管理
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.15.4" data-path="C02-Users/Address/UserAddressCode.html">
            
                
                    <a href="../../C02-Users/Address/UserAddressCode.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.4.</b>
                        
                        用户地址代码
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Goods/index.html">
            
                
                    <a href="../../C03-Goods/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        商品部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Goods/DatabaseDesign.html">
            
                
                    <a href="../../C03-Goods/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据表设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Goods/FastDFS.html">
            
                
                    <a href="../../C03-Goods/FastDFS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        FastDFS分布式文件系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Goods/Docker/index.html">
            
                
                    <a href="../../C03-Goods/Docker/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Docker使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="C03-Goods/Docker/Introduce.html">
            
                
                    <a href="../../C03-Goods/Docker/Introduce.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        Docker简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="C03-Goods/Docker/InstallAndOperations.html">
            
                
                    <a href="../../C03-Goods/Docker/InstallAndOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        安装与操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Goods/FastDFSDocker.html">
            
                
                    <a href="../../C03-Goods/FastDFSDocker.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        使用Docker安装FastDFS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="C03-Goods/FastDFSClientAndDjangoFileSystem.html">
            
                
                    <a href="../../C03-Goods/FastDFSClientAndDjangoFileSystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        FastDFS客户端与自定义文件存储系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="C03-Goods/CKEditor.html">
            
                
                    <a href="../../C03-Goods/CKEditor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        CKEditor富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="C03-Goods/ImportGoodsData.html">
            
                
                    <a href="../../C03-Goods/ImportGoodsData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        添加测试数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="C03-Goods/FreezeHTML.html">
            
                
                    <a href="../../C03-Goods/FreezeHTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        页面静态化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="C03-Goods/DjangoCrontab.html">
            
                
                    <a href="../../C03-Goods/DjangoCrontab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        定时任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="C03-Goods/GenerateIndexHTMLScript.html">
            
                
                    <a href="../../C03-Goods/GenerateIndexHTMLScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        静态化首页的手动脚本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="C03-Goods/GoodsDetail.html">
            
                
                    <a href="../../C03-Goods/GoodsDetail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        商品详情页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="C03-Goods/UserBrowseHistory.html">
            
                
                    <a href="../../C03-Goods/UserBrowseHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        用户浏览历史记录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="C03-Goods/GoodsList.html">
            
                
                    <a href="../../C03-Goods/GoodsList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        商品列表页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="C03-Goods/GoodsSearch.html">
            
                
                    <a href="../../C03-Goods/GoodsSearch.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        商品搜索
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-Cart/index.html">
            
                
                    <a href="../../C04-Cart/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        购物车部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-Cart/DataStructureDesign.html">
            
                
                    <a href="../../C04-Cart/DataStructureDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        购物车数据存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-Cart/Add.html">
            
                
                    <a href="../../C04-Cart/Add.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        购物车增加
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-Cart/Query.html">
            
                
                    <a href="../../C04-Cart/Query.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        购物车查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-Cart/Modify.html">
            
                
                    <a href="../../C04-Cart/Modify.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        购物车修改
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="C04-Cart/Delete.html">
            
                
                    <a href="../../C04-Cart/Delete.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        购物车删除
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="C04-Cart/SelectAll.html">
            
                
                    <a href="../../C04-Cart/SelectAll.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        购物车全选
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="C04-Cart/MergeCart.html">
            
                
                    <a href="../../C04-Cart/MergeCart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        登录合并购物车
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Order/index.html">
            
                
                    <a href="../../C05-Order/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        订单部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Order/OrderDBModel.html">
            
                
                    <a href="../../C05-Order/OrderDBModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        订单数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Order/PlaceOrder.html">
            
                
                    <a href="../../C05-Order/PlaceOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        订单结算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Order/SaveOrder.html">
            
                
                    <a href="../../C05-Order/SaveOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        保存订单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Order/OrderSuccess.html">
            
                
                    <a href="../../C05-Order/OrderSuccess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        下单成功
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Pay/index.html">
            
                
                    <a href="../../C06-Pay/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        支付宝支付
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Pay/Alipay.html">
            
                
                    <a href="../../C06-Pay/Alipay.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        接入支付宝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Pay/Paying.html">
            
                
                    <a href="../../C06-Pay/Paying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        发起支付
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Pay/PaymentResult.html">
            
                
                    <a href="../../C06-Pay/PaymentResult.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        保存支付结果
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-Xadmin.html">
            
                
                    <a href="../../C07-Xadmin.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Xadmin
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-Permission.html">
            
                
                    <a href="../../C08-Permission.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        用户权限控制
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >美多商城</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x7528;&#x6237;&#x5730;&#x5740;&#x7BA1;&#x7406;&#x4EE3;&#x7801;">&#x7528;&#x6237;&#x5730;&#x5740;&#x7BA1;&#x7406;&#x4EE3;&#x7801;</h1>
<h3 id="&#x540E;&#x7AEF;">&#x540E;&#x7AEF;</h3>
<p>&#x5728;users/views.py&#x4E2D;&#x6DFB;&#x52A0;&#x89C6;&#x56FE;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AddressViewSet</span><span class="hljs-params">(mixins.CreateModelMixin, mixins.UpdateModelMixin, GenericViewSet)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x5730;&#x5740;&#x65B0;&#x589E;&#x4E0E;&#x4FEE;&#x6539;
    &quot;&quot;&quot;</span>
    serializer_class = serializers.UserAddressSerializer
    permissions = [IsAuthenticated]

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_queryset</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">return</span> self.request.user.addresses.filter(is_deleted=<span class="hljs-keyword">False</span>)

    <span class="hljs-comment"># GET /addresses/</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">list</span><span class="hljs-params">(self, request, *args, **kwargs)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x7528;&#x6237;&#x5730;&#x5740;&#x5217;&#x8868;&#x6570;&#x636E;
        &quot;&quot;&quot;</span>
        queryset = self.get_queryset()
        serializer = self.get_serializer(queryset, many=<span class="hljs-keyword">True</span>)
        user = self.request.user
        <span class="hljs-keyword">return</span> Response({
            <span class="hljs-string">&apos;user_id&apos;</span>: user.id,
            <span class="hljs-string">&apos;default_address_id&apos;</span>: user.default_address_id,
            <span class="hljs-string">&apos;limit&apos;</span>: constants.USER_ADDRESS_COUNTS_LIMIT,
            <span class="hljs-string">&apos;addresses&apos;</span>: serializer.data,
        })

    <span class="hljs-comment"># POST /addresses/</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create</span><span class="hljs-params">(self, request, *args, **kwargs)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x4FDD;&#x5B58;&#x7528;&#x6237;&#x5730;&#x5740;&#x6570;&#x636E;
        &quot;&quot;&quot;</span>
        <span class="hljs-comment"># &#x68C0;&#x67E5;&#x7528;&#x6237;&#x5730;&#x5740;&#x6570;&#x636E;&#x6570;&#x76EE;&#x4E0D;&#x80FD;&#x8D85;&#x8FC7;&#x4E0A;&#x9650;</span>
        count = request.user.addresses.count()
        <span class="hljs-keyword">if</span> count &gt;= constants.USER_ADDRESS_COUNTS_LIMIT:
            <span class="hljs-keyword">return</span> Response({<span class="hljs-string">&apos;message&apos;</span>: <span class="hljs-string">&apos;&#x4FDD;&#x5B58;&#x5730;&#x5740;&#x6570;&#x636E;&#x5DF2;&#x8FBE;&#x5230;&#x4E0A;&#x9650;&apos;</span>}, status=status.HTTP_400_BAD_REQUEST)

        <span class="hljs-keyword">return</span> super().create(request, *args, **kwargs)

    <span class="hljs-comment"># delete /addresses/&lt;pk&gt;/</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">destroy</span><span class="hljs-params">(self, request, *args, **kwargs)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x5904;&#x7406;&#x5220;&#x9664;
        &quot;&quot;&quot;</span>
        address = self.get_object()

        <span class="hljs-comment"># &#x8FDB;&#x884C;&#x903B;&#x8F91;&#x5220;&#x9664;</span>
        address.is_deleted = <span class="hljs-keyword">True</span>
        address.save()

        <span class="hljs-keyword">return</span> Response(status=status.HTTP_204_NO_CONTENT)

    <span class="hljs-comment"># put /addresses/pk/status/</span>
<span class="hljs-decorator">    @action(methods=[&apos;put&apos;], detail=True)</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">status</span><span class="hljs-params">(self, request, pk=None)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x5730;&#x5740;
        &quot;&quot;&quot;</span>
        address = self.get_object()
        request.user.default_address = address
        request.user.save()
        <span class="hljs-keyword">return</span> Response({<span class="hljs-string">&apos;message&apos;</span>: <span class="hljs-string">&apos;OK&apos;</span>}, status=status.HTTP_200_OK)

    <span class="hljs-comment"># put /addresses/pk/title/</span>
    <span class="hljs-comment"># &#x9700;&#x8981;&#x8BF7;&#x6C42;&#x4F53;&#x53C2;&#x6570; title</span>
<span class="hljs-decorator">    @action(methods=[&apos;put&apos;], detail=True)</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">title</span><span class="hljs-params">(self, request, pk=None)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x4FEE;&#x6539;&#x6807;&#x9898;
        &quot;&quot;&quot;</span>
        address = self.get_object()
        serializer = serializers.AddressTitleSerializer(instance=address, data=request.data)
        serializer.is_valid(raise_exception=<span class="hljs-keyword">True</span>)
        serializer.save()
        <span class="hljs-keyword">return</span> Response(serializer.data)
</code></pre>
<p>&#x5728;users/serializers.py&#x4E2D;&#x6DFB;&#x52A0;&#x5E8F;&#x5217;&#x5316;&#x5668;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserAddressSerializer</span><span class="hljs-params">(serializers.ModelSerializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x5730;&#x5740;&#x5E8F;&#x5217;&#x5316;&#x5668;
    &quot;&quot;&quot;</span>
    province = serializers.StringRelatedField(read_only=<span class="hljs-keyword">True</span>)
    city = serializers.StringRelatedField(read_only=<span class="hljs-keyword">True</span>)
    district = serializers.StringRelatedField(read_only=<span class="hljs-keyword">True</span>)
    province_id = serializers.IntegerField(label=<span class="hljs-string">&apos;&#x7701;ID&apos;</span>, required=<span class="hljs-keyword">True</span>)
    city_id = serializers.IntegerField(label=<span class="hljs-string">&apos;&#x5E02;ID&apos;</span>, required=<span class="hljs-keyword">True</span>)
    district_id = serializers.IntegerField(label=<span class="hljs-string">&apos;&#x533A;ID&apos;</span>, required=<span class="hljs-keyword">True</span>)

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Meta</span>:</span>
        model = Address
        exclude = (<span class="hljs-string">&apos;user&apos;</span>, <span class="hljs-string">&apos;is_deleted&apos;</span>, <span class="hljs-string">&apos;create_time&apos;</span>, <span class="hljs-string">&apos;update_time&apos;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate_mobile</span><span class="hljs-params">(self, value)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x9A8C;&#x8BC1;&#x624B;&#x673A;&#x53F7;
        &quot;&quot;&quot;</span>
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> re.match(<span class="hljs-string">r&apos;^1[3-9]\d{9}$&apos;</span>, value):
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x624B;&#x673A;&#x53F7;&#x683C;&#x5F0F;&#x9519;&#x8BEF;&apos;</span>)
        <span class="hljs-keyword">return</span> value

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create</span><span class="hljs-params">(self, validated_data)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x4FDD;&#x5B58;
        &quot;&quot;&quot;</span>
        validated_data[<span class="hljs-string">&apos;user&apos;</span>] = self.context[<span class="hljs-string">&apos;request&apos;</span>].user
        <span class="hljs-keyword">return</span> super().create(validated_data)


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AddressTitleSerializer</span><span class="hljs-params">(serializers.ModelSerializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x5730;&#x5740;&#x6807;&#x9898;
    &quot;&quot;&quot;</span>
    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Meta</span>:</span>
        model = Address
        fields = (<span class="hljs-string">&apos;title&apos;</span>,)
</code></pre>
<p>&#x5728;users/urls.py&#x4E2D;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;</p>
<pre><code class="lang-python">router = routers.DefaultRouter()
router.register(<span class="hljs-string">r&apos;addresses&apos;</span>, views.AddressViewSet, base_name=<span class="hljs-string">&apos;addresses&apos;</span>)

urlpatterns += router.urls
<span class="hljs-comment"># POST /addresses/ &#x65B0;&#x5EFA;  -&gt; create</span>
<span class="hljs-comment"># PUT /addresses/&lt;pk&gt;/ &#x4FEE;&#x6539;  -&gt; update</span>
<span class="hljs-comment"># GET /addresses/  &#x67E5;&#x8BE2;  -&gt; list</span>
<span class="hljs-comment"># DELETE /addresses/&lt;pk&gt;/  &#x5220;&#x9664; -&gt; destroy</span>
<span class="hljs-comment"># PUT /addresses/&lt;pk&gt;/status/ &#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4; -&gt; status</span>
<span class="hljs-comment"># PUT /addresses/&lt;pk&gt;/title/  &#x8BBE;&#x7F6E;&#x6807;&#x9898; -&gt; title</span>
</code></pre>
<h3 id="&#x524D;&#x7AEF;">&#x524D;&#x7AEF;</h3>
<p>&#x4FEE;&#x6539;user_center_site.js&#x7684;mounted</p>
<pre><code class="lang-js">mounted: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        ...
        <span class="hljs-comment">// &#x8865;&#x5145;&#x83B7;&#x53D6;&#x5730;&#x5740;&#x6570;&#x636E;&#x7684;&#x8BF7;&#x6C42;</span>
        axios.get(<span class="hljs-keyword">this</span>.host + <span class="hljs-string">&apos;/addresses/&apos;</span>, {
                headers: {
                    <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                },
                responseType: <span class="hljs-string">&apos;json&apos;</span>
            })
            .then(response =&gt; {
                <span class="hljs-keyword">this</span>.addresses = response.data.addresses;
                <span class="hljs-keyword">this</span>.limit = response.data.limit;
                <span class="hljs-keyword">this</span>.default_address_id = response.data.default_address_id;
            })
            .catch(error =&gt; {
                status = error.response.status;
                <span class="hljs-keyword">if</span> (status == <span class="hljs-number">401</span> || status == <span class="hljs-number">403</span>) {
                    location.href = <span class="hljs-string">&apos;login.html?next=/user_center_site.html&apos;</span>;
                } <span class="hljs-keyword">else</span> {
                    alert(error.response.data.detail);
                }
            })
    },
</code></pre>
<p>&#x4FEE;&#x6539;user_center_site.js&#x7684;methods</p>
<pre><code class="lang-js">        <span class="hljs-comment">// &#x4FDD;&#x5B58;&#x5730;&#x5740;</span>
        save_address: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.error_receiver || <span class="hljs-keyword">this</span>.error_place || <span class="hljs-keyword">this</span>.error_mobile || <span class="hljs-keyword">this</span>.error_email || !<span class="hljs-keyword">this</span>.form_address.province_id || !<span class="hljs-keyword">this</span>.form_address.city_id || !<span class="hljs-keyword">this</span>.form_address.district_id ) {
                alert(<span class="hljs-string">&apos;&#x4FE1;&#x606F;&#x586B;&#x5199;&#x6709;&#x8BEF;&#xFF01;&apos;</span>);
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.form_address.title = <span class="hljs-keyword">this</span>.form_address.receiver;
                <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.editing_address_index === <span class="hljs-string">&apos;&apos;</span>) {
                    <span class="hljs-comment">// &#x65B0;&#x589E;&#x5730;&#x5740;</span>
                    axios.post(<span class="hljs-keyword">this</span>.host + <span class="hljs-string">&apos;/addresses/&apos;</span>, <span class="hljs-keyword">this</span>.form_address, {
                        headers: {
                            <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                        },
                        responseType: <span class="hljs-string">&apos;json&apos;</span>
                    })
                    .then(response =&gt; {
                        <span class="hljs-comment">// &#x5C06;&#x65B0;&#x5730;&#x5740;&#x6DFB;&#x52A0;&#x5927;&#x6570;&#x7EC4;&#x5934;&#x90E8;</span>
                        <span class="hljs-keyword">this</span>.addresses.splice(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, response.data);
                        <span class="hljs-keyword">this</span>.is_show_edit = <span class="hljs-literal">false</span>;
                    })
                    .catch(error =&gt; {
                        <span class="hljs-built_in">console</span>.log(error.response.data);
                    })
                } <span class="hljs-keyword">else</span> {

                    <span class="hljs-comment">// &#x4FEE;&#x6539;&#x5730;&#x5740;</span>
                    axios.put(<span class="hljs-keyword">this</span>.host + <span class="hljs-string">&apos;/addresses/&apos;</span> + <span class="hljs-keyword">this</span>.addresses[<span class="hljs-keyword">this</span>.editing_address_index].id + <span class="hljs-string">&apos;/&apos;</span>, <span class="hljs-keyword">this</span>.form_address, {
                        headers: {
                            <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                        },
                        responseType: <span class="hljs-string">&apos;json&apos;</span>
                    })
                    .then(response =&gt; {
                        <span class="hljs-keyword">this</span>.addresses[<span class="hljs-keyword">this</span>.editing_address_index] = response.data;
                        <span class="hljs-keyword">this</span>.is_show_edit = <span class="hljs-literal">false</span>;
                    })
                    .catch(error =&gt; {
                        alert(error.response.data.detail || error.response.data.message);
                    })
                }
            }
        },
        <span class="hljs-comment">// &#x5220;&#x9664;&#x5730;&#x5740;</span>
        del_address: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            axios.delete(<span class="hljs-keyword">this</span>.host + <span class="hljs-string">&apos;/addresses/&apos;</span> + <span class="hljs-keyword">this</span>.addresses[index].id + <span class="hljs-string">&apos;/&apos;</span>, {
                    headers: {
                        <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                    },
                    responseType: <span class="hljs-string">&apos;json&apos;</span>
                })
                .then(response =&gt; {
                    <span class="hljs-comment">// &#x4ECE;&#x6570;&#x7EC4;&#x4E2D;&#x79FB;&#x9664;&#x5730;&#x5740;</span>
                    <span class="hljs-keyword">this</span>.addresses.splice(index, <span class="hljs-number">1</span>);
                })
                .catch(error =&gt; {
                    <span class="hljs-built_in">console</span>.log(error.response.data);
                })
        },
        <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x5730;&#x5740;</span>
        set_default: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            axios.put(<span class="hljs-keyword">this</span>.host + <span class="hljs-string">&apos;/addresses/&apos;</span> + <span class="hljs-keyword">this</span>.addresses[index].id + <span class="hljs-string">&apos;/status/&apos;</span>, {}, {
                    headers: {
                        <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                    },
                    responseType: <span class="hljs-string">&apos;json&apos;</span>
                })
                .then(response =&gt; {
                    <span class="hljs-keyword">this</span>.default_address_id = <span class="hljs-keyword">this</span>.addresses[index].id;
                })
                .catch(error =&gt; {
                    <span class="hljs-built_in">console</span>.log(error.response.data);
                })
        },
        <span class="hljs-comment">// &#x5C55;&#x793A;&#x7F16;&#x8F91;&#x6807;&#x9898;</span>
        show_edit_title: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">this</span>.input_title = <span class="hljs-keyword">this</span>.addresses[index].title;
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;index; i++) {
                <span class="hljs-keyword">this</span>.is_set_title.push(<span class="hljs-literal">false</span>);
            }
            <span class="hljs-keyword">this</span>.is_set_title.push(<span class="hljs-literal">true</span>);
        } ,
        <span class="hljs-comment">// &#x4FDD;&#x5B58;&#x5730;&#x5740;&#x6807;&#x9898;</span>
        save_title: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.input_title) {
                alert(<span class="hljs-string">&quot;&#x8BF7;&#x586B;&#x5199;&#x6807;&#x9898;&#x540E;&#x518D;&#x4FDD;&#x5B58;&#xFF01;&quot;</span>);
            } <span class="hljs-keyword">else</span> {
                axios.put(<span class="hljs-keyword">this</span>.host + <span class="hljs-string">&apos;/addresses/&apos;</span> + <span class="hljs-keyword">this</span>.addresses[index].id + <span class="hljs-string">&apos;/title/&apos;</span>, {
                        title: <span class="hljs-keyword">this</span>.input_title
                    }, {
                        headers: {
                            <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + token
                        },
                        responseType: <span class="hljs-string">&apos;json&apos;</span>
                    })
                    .then(response =&gt; {
                        <span class="hljs-keyword">this</span>.addresses[index].title = <span class="hljs-keyword">this</span>.input_title;
                        <span class="hljs-keyword">this</span>.is_set_title = [];
                    })
                    .catch(error =&gt; {
                        <span class="hljs-built_in">console</span>.log(error.response.data);
                    })
            }
        },
        <span class="hljs-comment">// &#x53D6;&#x6D88;&#x4FDD;&#x5B58;&#x5730;&#x5740;</span>
        cancel_title: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">this</span>.is_set_title = [];
        }
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../C02-Users/Address/UserAddressManagement.html" class="navigation navigation-prev " aria-label="Previous page: 用户地址管理"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../C03-Goods/index.html" class="navigation navigation-next " aria-label="Next page: 商品部分"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
